import datetime
from typing import List
from pydantic import Field, BaseModel
from package.fastapi.schema import Page, BatchId


class _AgentConfigure(BaseModel):
    enabled: bool = Field(False, title='是否开启')
    configure: dict = Field({}, title='采集配置')

class AgentEdit(BaseModel):
    filebeat: _AgentConfigure = Field(None, title='心跳配置')
    winlogbeat: _AgentConfigure = Field(None, title='心跳配置')
    metricbeat: _AgentConfigure = Field(None, title='心跳配置')
    packetbeat: _AgentConfigure = Field(None, title='心跳配置')
    heartbeat: _AgentConfigure = Field(None, title='心跳配置')
    auditbeat: _AgentConfigure = Field(None, title='心跳配置')
    functionbeat: _AgentConfigure = Field(None, title='心跳配置')
    journalbeat: _AgentConfigure = Field(None, title='心跳配置')


class AgentOut(BaseModel):
    id: str = Field(..., title='ID')
    host: str = Field(None, title='主机')
    os: int = Field(..., title='系统')
    arch: bool = Field(..., title='架构')
    version: dict = Field(..., title='版本')
    status: dict = Field(..., title='代理状态')
    created_at: datetime.datetime = Field(None, title='')

    class Config:
        orm_mode = True
        extra = 'allow'
        json_encoders = {datetime.datetime: lambda dt: int(dt.timestamp() * 1000)}


class AgentItemOut(AgentOut, AgentEdit):
    pass

    class Config:
        orm_mode = True
        extra = 'allow'
        json_encoders = {datetime.datetime: lambda dt: int(dt.timestamp() * 1000)}


class PageAgent(Page):
    """获取页码条目"""
    data: List[AgentOut] = Field(..., title='')
